import { ErrorMsgEnum } from "/@/enums/httpEnum";
import { ElMessage } from 'element-plus';

export const showHttpErrorMessage = (err: any) => {
    let message = "请求失败";
    if(err?.response) {
        window.console.log('response',err?.response);
        const { data, status } = err.response;
        message = data?.message || "";
        if (!message) {
            switch (status) {
                case 400:
                    message = ErrorMsgEnum.ERROR_400;
                    break;
                case 401:
                    message = ErrorMsgEnum.ERROR_401;
                    break;
                case 403:
                    message = ErrorMsgEnum.ERROR_403;
                    break;
                case 404:
                    message = ErrorMsgEnum.ERROR_404;
                    break;
                case 500:
                    message = ErrorMsgEnum.ERROR_500;
                    break;
                case 502:
                    message = ErrorMsgEnum.ERROR_502;
                    break;
                case 503:
                    message = ErrorMsgEnum.ERROR_503;
                    break;
                case 504:
                    message = ErrorMsgEnum.ERROR_504;
                    break;
            }
        }
    } else {
        message = err.message
    }

    ElMessage.error(message);
};

export const showErrorMessage = (data: any) => {
    let message = data?.msg || "";
    ElMessage.error(message);
};